﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using NIIT.SaoBacDau.Aupi.HospitalManagement.Languages;
using NIIT.SaoBacDau.Aupi.HospitalManagement.Entities;
using NIIT.SaoBacDau.Aupi.HospitalManagement.BusinessLogic;

namespace NIIT.SaoBacDau.Aupi.HospitalManagement
{
    public partial class MedicalHistory : Form
    {
        private Pa_DetailsMedical pa_DetailsMedical;
        private Pa_Patient pa_Patient;
        public MedicalHistory()
        {
            InitializeComponent();
        }

        public MedicalHistory(Pa_DetailsMedical Pa_DetailsMedical,Pa_Patient pa_Pa)
        {
            InitializeComponent();
            this.pa_DetailsMedical = Pa_DetailsMedical;
            this.pa_Patient = pa_Pa;
        }

        private void tbn_CloseMedicalHistory_Click(object sender, EventArgs e)
        {
            if (LibraryLanguages.CancelUserControl("Lịch Sử Bệnh Án") == true)
                ((Managements)this.MdiParent).ShowPatient(HM_ReceptionAndManagementPatient.Patient_Search);
        }

       

        private void LoadTypeMedical()
        {
            List<F_TypeMedical> list = BL_F_TypeMedical.ListTypeMedical();
            for (int i = 0; i < list.Count; i++)
            {
                cbx_TypeMedical.Items.Add(list[i].NameMedical.ToString());
            }
            cbx_TypeMedical.SelectedIndex = 0;
        }

        private void TypeMedical(int typemedical)
        {
            if (typemedical == 0)
                ((Managements)this.MdiParent).LoadMedicalHistoryDetails(HM_TypeMedicalHistory.Bệnh_án_Nội_khoa);
            else if (typemedical == 1)
                ((Managements)this.MdiParent).LoadMedicalHistoryDetails(HM_TypeMedicalHistory.Bệnh_án_Nhi_khoa);
            else if (typemedical == 2)
                ((Managements)this.MdiParent).LoadMedicalHistoryDetails(HM_TypeMedicalHistory.Bệnh_án_Truyền_nhiễm);
            else if (typemedical == 3)
                ((Managements)this.MdiParent).LoadMedicalHistoryDetails(HM_TypeMedicalHistory.Bệnh_án_Phụ_khoa);
            else if (typemedical == 4)
                ((Managements)this.MdiParent).LoadMedicalHistoryDetails(HM_TypeMedicalHistory.Bệnh_án_Sản_khoa);
        }

        private void MedicalHistory_Load(object sender, EventArgs e)
        {
            LoadTypeMedical();
            LoadPatient(pa_Patient);
        }

        private void LoadPatient(Pa_Patient pa_Patient)
        {
            tbx_PatientName.Text = pa_Patient.Name;
            tbx_BirthDay.Text = pa_Patient.BirthDay;
            if (pa_Patient.Gender == true)
                rbtn_Male.Checked = true;
            else
                rbtn_Women.Checked = true;
            tbx_Ethnic.Text = pa_Patient.Ethnic;
            tbx_HouseID.Text = pa_Patient.HouseID.ToString();
            tbx_Stress.Text = pa_Patient.Stress;
            tbx_Ward.Text = pa_Patient.Ward;
            tbx_District.Text = pa_Patient.District;
            tbx_City.Text = pa_Patient.City;
            tbx_Occupation.Text = pa_Patient.Occupation;
            tbx_AddressOccupation.Text = pa_Patient.AddressOccupation;
            tbx_ContactPhone.Text = pa_Patient.ContactPhone;
            tbx_TypeObject.Text = pa_Patient.TypePatient;
            tbx_InsuranceID.Text = pa_Patient.Cardnumber;
            tbx_HospitalizedDate.Text = pa_Patient.HospitalizedDate;
            tbx_States.Text = pa_Patient.States;
            D_OrganizationDetails d_Org = new D_OrganizationDetails();
            d_Org.OrganizationDetailsID = pa_Patient.OrganizationDetailsID;
            tbx_DepartmentName.Text = BL_D_OrganizationDetailss.ObjOrganizationDetails(d_Org).NameDetails;
            string date = String.Format("{0:yyyy/MM/dd HH:mm:ss}", DateTime.Now).ToString();
            tbx_DischargeDate.Text = date;
        }

        private void btn_Next_Click(object sender, EventArgs e)
        {
            TypeMedical(cbx_TypeMedical.SelectedIndex);
        }

        private void btn_Cancel_Click(object sender, EventArgs e)
        {
            if (LibraryLanguages.CloseMedicalHistory() == true)
                ((Managements)this.MdiParent).ShowPatient(HM_ReceptionAndManagementPatient.Patient_MedicalHistory);
        }

        private void btn_Previous_Click(object sender, EventArgs e)
        {
            ((Managements)this.MdiParent).ShowPatient(HM_ReceptionAndManagementPatient.Patient_Search);
        }
    }
}
